package HP.yrr;

import java.util.Scanner;

public class Test {

    public static void myStart() throws Exception {

        Scanner sc = new Scanner(System.in);
        System.out.println("输入文件路径:");
        String str = sc.nextLine();
        String str1 = "/";
        String str2 = "\\";

        // System.out.println(str.indexOf('/'));
        // System.out.println(str.indexOf('/')+1);

        // String str3 = str.substring(str.indexOf('/'),str.indexOf('/')+1);
        // System.out.println(str3);
        int iZ = str.lastIndexOf('/');
        int iF = str.lastIndexOf('\\');
        System.out.println("iZ = " + iZ);
        System.out.println("iF = " + iF);


        if ((iZ != -1) && (iF == -1)) { //处理 C:/java/kk.txt
            System.out.println("(//处理 C:/java/kk.txt)获取文件名:" + str.substring(iZ + 1));
            if (str1.equals(str.substring(iZ, (iZ + 1)))) {
                System.out.println("str = " + str);
                System.out.println("文件名:" + showZAFN(str));
                System.out.println("22" + showZFKZM(str));
                System.out.println("33" + showZFN(str));
            }
        } else if ((iZ == -1) && (iF != -1)) {//处理 C:\\java\\kk.txt
            System.out.println("(处理 C:\\\\java\\\\kk.txt)获取文件名:" + str.substring(iF + 1));
            if (str2.equals(str.substring(iF, (iF + 1)))) {
                System.out.println("str = " + str);
                System.out.println("文件名:" + showFAFN(str));
                System.out.println("2" + showFFKZM(str));
                System.out.println("3" + showFFN(str));
            }
        } else {
            System.out.println("这不是一个正确的路径");
        }
    }



/*        if ((str.lastIndexOf('/') != -1) && ((str.lastIndexOf('/') - 1)) != -1) {
            if (str2.equals(str.substring(str.lastIndexOf('\\'), str.lastIndexOf('\\') - 1))) {
                showFAFN(str);
                showFFKZM(str);
                showFFN(str);
            } else if (str1.equals(str.substring(str.lastIndexOf('/'), str.lastIndexOf('/') - 1))) {
                System.out.println("11111");
                System.out.println(showZAFN(str));
                showZFKZM(str);
                showZFN(str);
            }
        } else {
            System.out.println("这不是一个正确的路径");
        }
    }*/
/*        if (str.lastIndexOf('/') == -1) {
            if (str2.equals(str.substring(str.lastIndexOf('\\'), str.lastIndexOf('\\') - 1))) {
                showFAFN(str);
                showFFKZM(str);
                showFFN(str);
            }
        } else if (str1.equals(str.substring(str.lastIndexOf('/'), str.lastIndexOf('/') - 1))) {
            // DataFile ffs = new FileForwardSlash(str);
            // File file = new File();
            // file.showFileAllName(ffs);
            System.out.println("11111");
            System.out.println(showZAFN(str));
            showZFKZM(str);
            showZFN(str);
        }
    }*/

    public static String showZAFN(String str) {
        return str.substring(str.lastIndexOf('/') + 1);
    }

    public static String showZFN(String str) {
        return str.substring(str.lastIndexOf('/') + 1, str.lastIndexOf('.'));
    }

    public static String showZFKZM(String str) {
        return str.substring(str.lastIndexOf('.') + 1);
    }

    public static String showFAFN(String str) {
        return str.substring(str.lastIndexOf('\\') + 1);
    }

    public static String showFFN(String str) {
        return str.substring(str.lastIndexOf('\\') + 1, str.lastIndexOf('.'));
    }

    public static String showFFKZM(String str) {
        return str.substring(str.lastIndexOf('.') + 1);
    }

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        myStart();
    }

}
